import React, { Component } from 'react';
import { Row, Col } from 'antd';
import { withRouter } from 'react-router-dom';
import { WindManUtils } from '../../util/utils';
import './index.less';

class Wheaders extends Component {
    constructor(props) {
        super(props);
        this.state = {
            Wleft : props.left,
            Wmiddle : props.middle,
            Wright : props.right,
        }
    }

    render() {
        return (
            <div className='header'>
                <div className={'header'} onClick={this.handleJump.bind(this)}>
                    <Row>
                        <Col className={'return'} span={'8'} data-jump = {this.state.Wleft}>
                            {this.state.Wleft || 'Windmao'}
                        </Col>
                        <Col className={'title'} span={'8'} >
                            {this.state.Wmiddle || ''}
                        </Col>
                        <Col className={'home'} span={'8'} data-jump={this.state.Wright}>
                            {this.state.Wright || '登录'}
                        </Col>
                    </Row>
                </div>
            </div>
        );
    }

    UNSAFE_componentWillMount() {

    }

    componentDidMount () {
        if ( !WindManUtils.getStorage('user_info') && this.state.Wright !== '首页') {
            this.setState({ Wright: '登录' });
        }
    }

    handleJump(e) {

        if (e.target.getAttribute('data-jump') === '返回') {
            this.props.history.goBack();
        }
        else if (e.target.getAttribute('data-jump') === '登录') {
            WindManUtils.removeAllStorage();
            this.props.history.push('/login');
        }
        else if (e.target.getAttribute('data-jump') === '首页') {
            this.props.history.push('/');
        }
        else if (e.target.getAttribute('data-jump') === '我的') {
            this.props.history.push('/usercenter');
        }
        else if (e.target.getAttribute('data-jump') === '搜索') {
            this.props.history.push('/search');
        }
    }


}
export default withRouter(Wheaders);


